﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using DemoUser.Application.User.Dtos;
using DemoUser.Application.User.Interface;
using DemoUser.Core.User;

using StackExchange.Profiling.Internal;

namespace DemoUser.Application.User
{
    public class TestAppService:IDynamicApiController
    {
        private readonly ITestService _testService;

        public TestAppService(ITestService testService)
        {
            _testService = testService;
        }

        /// <summary>
        /// 查询所有
        /// </summary>
        /// <returns></returns>
        public List<TbUser> GetAll()
        {
            return _testService.SelectAll();
        }

        /// <summary>
        /// 查总数
        /// </summary>
        /// <returns></returns>
        public int GetCount()
        {
            return _testService.SelectCount();
        }

        /// <summary>
        /// 单条件查询
        /// </summary>
        public List<TbUser> GetByUsername(string username)
        {
            return _testService.SelectByUsername(username);
        }

        /// <summary>
        /// 多条件查询
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public List<TbUser> GetByUsernameAndPassword(string username, string password)
        {
            return _testService.SelectByUsernameAndPassword(username, password);
        }

        /// <summary>
        /// 模糊查询
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public List<TbUser> GetLikeUsername(string username)
        {
            return _testService.SelectLikeUsername(username);
        }

        /// <summary>
        /// 根据主键查询
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public TbUser GetById(int id)
        {
            return _testService.SelectById(id);
        }

        /// <summary>
        /// 查询第一个
        /// </summary>
        /// <returns></returns>
        public TbUser GetFirst()
        {
            return _testService.SelectFirst();
        }

        /// <summary>
        /// 查询前几个
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        public List<TbUser> GetCounts(int count) {
            return _testService.SelectCount(count);
        }

        /// <summary>
        /// 查询最后一个
        /// </summary>
        /// <returns></returns>
        public TbUser GetLast()
        {
            return _testService.SelectLast();
        }

        /// <summary>
        /// 查询是否存在
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool IsExist([FromQuery]TbUser user)
        {
            return _testService.IsExist(user);
        }

        /// <summary>
        /// in查询（单个字段）
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public List<TbUser> GetInUsername(string[] username) { 
            return _testService.SelectInUsername(username);
        }

        /// <summary>
        /// in查询（多个字段）
        /// </summary>
        /// <param name="tbUsers"></param>
        /// <returns></returns>
        public List<TbUser> GetInUsernameAndPassword([FromQuery]TbUser[] tbUsers)
        {
            Console.WriteLine(tbUsers.ToJson());
            return _testService.SelectInUsernameAndPassword(tbUsers);
        }

        /// <summary>
        /// 查询时忽略某个字段
        /// </summary>
        /// <returns></returns>
        public List<TbUser> GetNotPassword()
        {
            return _testService.SelectNotPassword();
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="pageNum"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public List<TbUser> GetByPage(int pageNum,int pageSize) { 
            return _testService.SelectByPage(pageNum,pageSize);
        }

        /// <summary>
        /// 按id分组查询
        /// </summary>
        /// <returns></returns>
        public List<TbUserDto> GroupById()
        {
            return _testService.SelectGroupById();
        }

        /// <summary>
        /// 插入数据
        /// </summary>
        /// <param name="tbUser"></param>
        [HttpPost]
        public void InsertOne([FromQuery] TbUser tbUser)
        {
            _testService.InsertOne(tbUser);
        }

        /// <summary>
        /// 批量修改密码
        /// </summary>
        [HttpPut]
        public void UpdatePassword()
        {
            _testService.UpdatePassword();
        }


        /// <summary>
        /// 根据id删除单条数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public int DelById(int id)
        {
            return _testService.DelById(id);
        }

        /// <summary>
        /// 根据id数组批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpDelete]
        public int DelByIds(int[] ids) { 
            return _testService.DelByIds(ids);
        }
    }
}
